package com.example.demo.controller;

import com.example.demo.model.Classes;
import com.example.demo.service.ClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @RestController 注解后，可以使后面的方法不需要显式加@ResponseBody注解
 */
@RestController
@RequestMapping("/class")
public class ClassesController {
    @Autowired
    private ClassesService classesService;
    @RequestMapping("/selectAll")
    public List<Classes> selectAll(){

        return classesService.selectAll();
    }

    /**
     * 使用@RequestParam注解 用Map接收请求参数
     * @param map
     * @return
     */
    @RequestMapping("/selectByCon")
    public List<Classes> selectByCon(@RequestParam HashMap<String, Object> map){

        return classesService.selectByParamMap((HashMap<String, Object>) map);
    }
    @RequestMapping("/getByKey")
    public Classes getByKey(@RequestParam("id") Integer id){
        return classesService.selectByPrimaryKey(id);
    }
    @RequestMapping("/insert")
    public List<Classes> insert(Classes classes){
        classesService.insert(classes);
        return classesService.selectAll();
    }
    @RequestMapping("/update")
    public List<Classes> update(Classes classes){
        classesService.updateByPrimaryKey(classes);
        return classesService.selectAll();
    }
    @RequestMapping("/delete")
    public int delete(@RequestParam("id") Integer id){
        return classesService.deleteByPrimaryKey(id);
    }
}
